<?php
namespace App\Repositories;

use App\Models\Composite;
use App\Models\Simulate;
use App\Repositories\PracticeRepository;

class CompositeRepository extends BaseRepository
{

    protected $practice;
    public function __construct(
        Composite $composite,
        PracticeRepository $practice
    )
    {
        $this->model = $composite;
        $this->practice = $practice;
    }


    /**
     * 获取章节列表信息
     * @param array $data
     * @param array|string $extra
     * @param string $size
     * @return string
     */
    public function index($data, $extra = '', $size = '')
    {
        //获取科目的章节列表
        $chapter_list = $this->model->where([['pid', $data['km']], ['sid', '1']])->get()->toArray();

//        if($chapter_list){
//            foreach($chapter_list as $key => $value){
//                $chapter_list[$key]['total'] = Simulate::where([['pid', $data['km']], ['mid', $value['id']], ['stauts', '1']])->count();
//                $chapter_list[$key]['simulate'] = $this->practice->getSimulateID([['mid', $value['id']]], null);
//            }
//        }
        return $chapter_list;
    }

    /**
     * 存储odb
     * @param $inputs
     */
    public function store($inputs, $extra = '')
    {

    }

    /**
     * 更新
     * @param $id
     * @param $input
     * @return mixed
     */
    public function update($id, $input,$extra = '')
    {
        $model = $this->getById($id);
        return $this->save($model,$input);
    }


    /**
     * 编辑特定id资源
     * @param  int $id 资源id
     * @param  string|array $extra 可选额外传入的参数
     * @return Illuminate\Support\Collection
     */
    public function edit($id, $extra)
    {

    }

    /**
     * @param $model
     * @param $inputs
     * @param bool $falg
     * @return mixed
     */
    public function save($model , $inputs , $falg = false)
    {
        return $model;
    }

}